/*IWpR2doUeFvfcO3sMbniflNH0Ki5BQM55aQabr1fER0H9E4L+JUdz5T8Uk+lXXWO*/
import { ajax, getBusinessInfo } from 'nc-lightapp-front';

function pubBeforeEvent(that, props, moduleId, key, value, data, cytjCode, bfCode, dfCode, publicCode) {

    let meta = props.meta.getMeta()
    //本方交易类型
    if (key == 'jfTradeRef') {
        let jfBillTypeBox = props.form.getFormItemsValue(cytjCode, 'jfBillTypeBox').value;
        if (jfBillTypeBox == 'gysfk') {
            meta[bfCode].items.map((item) => {
                if (item.attrcode == 'jfTradeRef') {
                    item.queryCondition = () => {
                        return {
                            parentbilltype: 'F3' //过滤条件
                        };
                    }
                }
                return item;
            })
        } else if (jfBillTypeBox == 'khys') {
            meta[bfCode].items.map((item) => {
                if (item.attrcode == 'jfTradeRef') {
                    item.queryCondition = () => {
                        return {
                            parentbilltype: 'F0' //过滤条件
                        };
                    }
                }
                return item;
            })
        }
    }

    //对方交易类型
    if (key == 'dfTradeRef') {
        let dfBillTypeBox = props.form.getFormItemsValue(cytjCode, 'dfBillTypeBox').value;
        if (dfBillTypeBox == 'khsk') {
            meta[dfCode].items.map((item) => {
                if (item.attrcode == 'dfTradeRef') {
                    item.queryCondition = () => {
                        return {
                            parentbilltype: 'F2' //过滤条件
                        };
                    }
                }
                return item;
            })
        } else if (dfBillTypeBox == 'gysyf') {
            meta[dfCode].items.map((item) => {
                if (item.attrcode == 'dfTradeRef') {
                    item.queryCondition = () => {
                        return {
                            parentbilltype: 'F1' //过滤条件
                        };
                    }
                }
                return item;
            })
        }
    }

    //部门
    if (key == 'deptRef') {
        meta[publicCode].items.map((item) => {
            if (item.attrcode == 'deptRef') {
                item.isShowUnit = true,
                    item.unitCondition = () => {
                        return {
                            pkOrgs: props.form.getFormItemsValue(moduleId, 'pk_org') ? props.form.getFormItemsValue(moduleId, 'pk_org').value : null,
                            TreeRefActionExt: 'nccloud.web.arap.ref.before.OrgSqlBuilder'
                        }
                    }
                item.queryCondition = () => {
                    return {
                        busifuncode: 'all',
                        DataPowerOperationCode: 'fi',//使用权组
                        isDataPowerEnable: 'Y',
                        VersionStartDate: getBusinessInfo().businessDate,
                        pk_org: props.form.getFormItemsValue(moduleId, 'pk_org') ? props.form.getFormItemsValue(moduleId, 'pk_org').value : null
                    };
                }
            }
            return item;
        })
    }

    //表头科目,表体科目
    if (key == 'headSubjRef' || key == 'itemSubjRef') {
        ajax({
            url: '/nccloud/arap/arappub/arapQueryAccountBookAction.do',
            data: {
                pk_org: props.form.getFormItemsValue(moduleId, 'pk_org') ? props.form.getFormItemsValue(moduleId, 'pk_org').value : null,
            },
            async: false,
            success: (res) => {
                if (res.success) {
                    meta[publicCode].items.map((item) => {
                        if (item.attrcode == 'headSubjRef' || item.attrcode == 'itemSubjRef') {
                            item.queryCondition = () => {
                                return {
                                    DataPowerOperationCode: 'fi',//使用权组
                                    isDataPowerEnable: 'Y',
                                    pk_accountingbook: res.data,
                                    datestr: getBusinessInfo().businessDate
                                }
                            }
                        }
                        return item;
                    })
                }
            }
        });
    }

    props.meta.setMeta(meta);
}


export { pubBeforeEvent }
/*IWpR2doUeFvfcO3sMbniflNH0Ki5BQM55aQabr1fER0H9E4L+JUdz5T8Uk+lXXWO*/